'''
__author__ = 'xxz'
__email__ = 'talos.tse@gmail.com'
Created on '2013/12/04 16:23'
'''


from multiprocessing import Pool
from time import time
import socket
import urllib2
import sgmllib
import re
import Queue

#hostList = ['www.sina.com.cn', 'www.163.com', 'www.baidu.com', 'www.cnblogs.com', 'www.qq.com', 'www.douban.com', 'www.google.com', 'www.google.ru', 'www.apple.com', 'www.battle.net', 'www.duowan.com', 'www.live.com']
hostList = ['image.baidu.com']


def worker(i):
    ip = socket.gethostbyname(i)
    print "%s : %s " % (i, ip)
    req = urllib2.Request('http://'+i)
    content = urllib2.urlopen(req).read()
    print(content)

def main():
    pool = Pool(processes=10)
    for i in hostList:
        result = pool.apply_async(worker, (i,))
    pool.close()
    pool.join()
    print(result)

    if result.successful():
        print('successful')

if __name__ == '__main__':
    main()

